import java.util.Objects;

/**
 * @User: vitobo
 * @Date: 2024-05-24
 * @Description: Object类
 */


class Person{
    private String name;
    private int age;

    public Person(String name, int age){
        this.age = age;
        this.name = name;
    }

    @Override
    public boolean equals(Object obj){
        if(obj==null){
            return false;
        }
        if(this == obj){
            return true;
        }
        if(!(obj instanceof Person)){
            return false;
        }

        // 向下转型,比较属性值
        Person person = (Person)obj;
        return this.name.equals(person.name) && this.age==person.age;
    }

    // hashcode方法用来确定对象在内存中存储的位置是否相同
    @Override
    public int hashCode(){
        return Objects.hash(name, age);
    }
}


public class Test5 {
    public static void main(String[] args) {
        int a = 10;
        int b = 10;

        Person p1 = new Person("bobo", 22);
        Person p2 = new Person("bobo", 22);

        System.out.println(p1.hashCode());
        System.out.println(p2.hashCode());



//        System.out.println(a==b);
//        System.out.println(p1==p2);
//        System.out.println(p1.equals(p2));
    }
}
